<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/11/2
 * Time: 17:24
 */

namespace App\Admin\Models;

use Encore\Admin\Traits\ModelTree;

/**
 * App\Admin\Models\PositionModel
 *
 * @property int $position_id 职位ID
 * @property int $parent_id 父ID
 * @property int $order 排序
 * @property string $name_zh 职位名称-中文
 * @property string $name_en 职位名称-英文
 * @property \Illuminate\Support\Carbon $created_at 创建时间
 * @property \Illuminate\Support\Carbon $updated_at 最后更新时间
 * @property-read \Illuminate\Database\Eloquent\Collection|PositionModel[] $children
 * @property-read int|null $children_count
 * @property-read PositionModel $parent
 * @method static \Illuminate\Database\Eloquent\Builder|PositionModel newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|PositionModel newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|PositionModel query()
 * @method static \Illuminate\Database\Eloquent\Builder|PositionModel whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|PositionModel whereNameEn($value)
 * @method static \Illuminate\Database\Eloquent\Builder|PositionModel whereNameZh($value)
 * @method static \Illuminate\Database\Eloquent\Builder|PositionModel whereOrder($value)
 * @method static \Illuminate\Database\Eloquent\Builder|PositionModel whereParentId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|PositionModel wherePositionId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|PositionModel whereUpdatedAt($value)
 * @mixin \Eloquent
 */
class PositionModel extends BaseModel
{
    use ModelTree;

    protected $table = 'admin_positions';

    protected $primaryKey = 'position_id';

    /**
     * SequenceModel constructor.
     *
     * @param array $attributes
     */
    public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);

        $this->setTitleColumn('name_zh');
    }

    /**
     * 获取职位列表列表
     *
     * @return array
     */
    public static function getPositionList()
    {
        $list = static::select(['position_id', 'name_zh'])->orderBy('order', 'asc')->orderBy('position_id', 'desc')->get();

        return !empty($list) ? json_decode(json_encode($list), true) : [];
    }
}
